export default app => {
  const { STRING, INTEGER, DATE, TEXT } = app.Sequelize;

  const Company = app.model.define('Company', {
    id: { type: INTEGER, primaryKey: true, autoIncrement: true },
    uuid: { type: STRING(36), unique: true },
    name: STRING(50), // 企业名称
    address: STRING(255), // 企业地址
    /** 组织机构代码 */
    companyNum: {
      type: STRING(50),
      field: 'company_num'
    },
    /** 医疗领域 */
    medicalField: {
      type: STRING(36),
      field: 'medical_field',
    },
    /** 企业类型 */
    type: {
      type: STRING(36),
      field: 'type',
    },
    createTime: DATE, // 公司建立时间
    description: TEXT, // 公司简介
    filler: {
      type: STRING(36),
    }, // 填写人
    updateTime: DATE, // 更新日期
    createdAt: DATE,
    updatedAt: DATE,
  }, {
    tableName: 'company'
  });

  Company.associate = () => {
    app.model.Company.belongsToMany(app.model.MainBusiness, {
      through: app.model.MergeCompanyMainbusiness,
      foreignKey: 'fk_company_id',
      targetKey: 'id',
    });
    app.model.Company.belongsTo(app.model.MedicalField, {
      foreignKey: 'medical_field',
      targetKey: 'uuid',
    });
    app.model.Company.belongsTo(app.model.CompanyType, {
      foreignKey: 'type',
      targetKey: 'uuid',
    });
  };
  return Company;
};
